package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.display.newAttack.vo.FriendVo;
	import engine.event.SceneEvent;
	import engine.logic.LogSendLogic;
	import engine.net.datatype.WString;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.comboBox.NxComboBoxEvent;
	import newx.com.control.window.NxWindowEvent;
	import newx.utils.FilterUtil;

	public class EscortLogic
	{
		private static var _self		:EscortLogic;
		private var _myDis				:EscortUI;
		
		private var _bindManage		:BindManage;
		private var _model				:ModelLocator;
		private var _playerConvoyIndex	:int
		private var _playerConvoyExciteCount:int;
		private var _friendObj			:Object;
		private var _friendListArray	:Array
		private var _maxNum			:int		=	5;
		private var _countMax			:int		=	5;
		private var _countIndex		:int		=	0;
		private var _playerConvoyCall	:int		=	0;
		private var _playerConvoyMoney	:int		=	0;
		private var _chooseFriendVo	:FriendVo	=	null;
		private var _chooseFriendObj	:Object		=	null
		private var _convoyObj			:Object		=	{}
		private var _convoyArray		:Array		=	[];
		private var _isBind			:Boolean	=	false;
		private var _reshHeroID		:int		=	5
			
		private var _helpTime			:int		=	0;
		private var _time				:Timer;
		//奖励加成
		private var _addPer			:Number;
		public function EscortLogic()
		{
			_myDis		=	EscortUI.getInstance();
			init();
		}
		public static function getInstance():EscortLogic
		{
			if(_self == null)
			{
				_self	=	new EscortLogic();
			}
			return _self;
		}
		/**
		 * 添加事件
		 */		
		public function addListener():void
		{
			
			
			_myDis.p1.source	=	ResPath.SWF	+	"movemoneycar_1.swf";
			_myDis.p2.source	=	ResPath.SWF	+	"movemoneycar_2.swf";
			_myDis.p3.source	=	ResPath.SWF	+	"movemoneycar_3.swf";
			_myDis.p4.source	=	ResPath.SWF	+	"movemoneycar_4.swf";
			_myDis.p5.source	=	ResPath.SWF	+	"movemoneycar_5.swf";
			
			_myDis	.windowBG		.addEventListener(NxWindowEvent.WINDOW_CLOSE,			windowClose);
			_myDis	.sendBtn		.addEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.refhBtn		.addEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.heroHelpBtn	.addEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.friendBtn		.addEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.chooseHeroBtn	.addEventListener(MouseEvent.CLICK, 					btnClickHandle);
			
			_myDis	.chooseHeroBtn	.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.refhBtn		.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.heroHelpBtn	.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			

			
			_myDis	.chooseHeroBtn	.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.refhBtn		.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.heroHelpBtn	.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			
			_myDis	.p1				.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.p2				.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.p3				.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.p4				.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			_myDis	.p5				.addEventListener(MouseEvent.MOUSE_OVER, 				btnOverClickHandle);
			
			_myDis	.p1				.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p2				.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p3				.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p4				.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p5				.addEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			
			_model					.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_REQUEST_CHARGE),upDataMoney);
			_model					.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMS_GET_CONVOYHELPERREC),upFriednHelpList);

			_myDis	.friendBox	.addEventListener(NxComboBoxEvent.NXCOMBOBOX_CLICK, 	comBoxClickHandle);
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CHARGE,_reshHeroID);
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMS_GET_CONVOYHELPERREC);
			_myDis	.friendBox	.setSelected(0)
			if(!_isBind)
			{
				//是否有战神 	
				_bindManage.BindProp(_model.scene.Role,"PlayerConvoyCall",this,"playerConvoyCall");
				//当前的护送使者
				_bindManage.BindProp(_model.scene.Role,"PlayerConvoyIndex",this,"playerConvoyIndex");
				//鼓励等级 
				_bindManage.BindProp(_model.scene.Role,"PlayerConvoyExciteCount",this,"playerConvoyExciteCount");
				//VIP等级
				_bindManage.BindProp(_model.scene.Role,"VIPLevel",this,"vipLevel");
//				_bindManage.BindRecord(_model.scene,"Friend",addFriend,removeFriend);
				_isBind	=	true
			}
			getOut();
		}
		/**
		 * 关闭事件
		 */		
		public function removeListener():void
		{
			
			_myDis	.windowBG		.addEventListener(NxWindowEvent.WINDOW_CLOSE,			windowClose);
			_myDis	.sendBtn		.removeEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.refhBtn		.removeEventListener(MouseEvent.CLICK,					btnClickHandle);
			_myDis	.friendBtn		.removeEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.heroHelpBtn	.removeEventListener(MouseEvent.CLICK, 					btnClickHandle);
			_myDis	.chooseHeroBtn	.removeEventListener(MouseEvent.CLICK, 					btnClickHandle);
			
			_myDis	.chooseHeroBtn	.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.refhBtn		.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.heroHelpBtn	.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			
			_myDis	.chooseHeroBtn	.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.refhBtn		.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.heroHelpBtn	.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			
			_myDis	.p1				.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.p2				.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.p3				.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.p4				.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			_myDis	.p5				.removeEventListener(MouseEvent.MOUSE_OVER, 			btnOverClickHandle);
			
			_myDis	.p1				.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p2				.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p3				.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p4				.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_myDis	.p5				.removeEventListener(MouseEvent.MOUSE_OUT, 				btnOutClickHandle);
			_model					.removeEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_REQUEST_CHARGE),upDataMoney);
			_myDis	.friendBox	.removeEventListener(NxComboBoxEvent.NXCOMBOBOX_CLICK, 	comBoxClickHandle);
			if(_chooseFriendObj != null)
			{
				SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_HELP_CONVOY,[2,new WString(_chooseFriendObj["name"])]);
				getOut();
			}
			
		}
		/**
		 * 当前护送的使者
		 * @param val
		 */		
		public function set playerConvoyIndex(val:int):void
		{
			_playerConvoyIndex	=	val;
			_playerConvoyIndex	=	_playerConvoyIndex<=0?1:_playerConvoyIndex;
			_addPer				=	0;
			if(_convoyObj != null)
			{
				
				_convoyArray	=	String(_convoyObj[_playerConvoyIndex]).split(",");
				_myDis.timeLabel.htmlText	=	StaticIni.getSwfLangStrVar("EscortStr_21",[_convoyArray[6]]);
				//是否是本人招的战神
				if(_playerConvoyCall)
				{
					_addPer	+= 100;
//					_myDis.moneyLabel.htmlText	=	StaticIni.getSwfLangStrVar("EscortStr_22",[_convoyArray[0] * _model.scene.Role.getPlayerLevel() + int(_convoyArray[1]),_convoyArray[2]]) + "(+100%)";
				}
				else
				{
					//别人的
					if( EscortSceneLogic.getInstance().addRoRemove != -1 )
					{
						_addPer += 20;
//						_myDis.moneyLabel.htmlText	=	StaticIni.getSwfLangStrVar("EscortStr_22",[_convoyArray[0] * _model.scene.Role.getPlayerLevel() + int(_convoyArray[1]),_convoyArray[2]]) + "(+20%)";

					}//else
//					{
//						_myDis.moneyLabel.htmlText	=	StaticIni.getSwfLangStrVar("EscortStr_22",[_convoyArray[0] * _model.scene.Role.getPlayerLevel() + int(_convoyArray[1]),_convoyArray[2]]);

//					}
				}
				//有没有在活动中
				if( EscortSceneLogic.getInstance().coveryActive == 1 ||  EscortSceneLogic.getInstance().coveryActive == 2)
				{
					_addPer += 20;
				}
				//有没有在春节活动中
				if(EscortSceneLogic.getInstance().springFestival)
				{
					_addPer += 50;
				}
				var _addStr:String = _addPer == 0 ? "" :  ("(+" + _addPer + "%)");
				_myDis.moneyLabel.htmlText	=	StaticIni.getSwfLangStrVar("EscortStr_22",[_convoyArray[0] * _model.scene.Role.getPlayerLevel() + int(_convoyArray[1]),_convoyArray[2]]) + _addStr;
			}
			setEffect(_playerConvoyIndex);
			_myDis.currLabel.htmlText = StaticIni.getSwfLangStrVar("UIString_1000538", [StaticIni.getSwfLangStr("EscortName_0"+ _playerConvoyIndex)]);
		}
		/**
		 * 鼓励等级 
		 * @param val
		 * 
		 */		
		public function set playerConvoyExciteCount(val:int):void
		{
			_playerConvoyExciteCount	=	val;
			if(_playerConvoyExciteCount >=5)
			{
				_myDis.heroHelpBtn.enabled	=	false;
			}
			else
			{
				_myDis.heroHelpBtn.enabled	=	true;
			}
			_myDis.heroLabel.htmlText		=	StaticIni.getSwfLangStrVar("EscortStr_23",[val * 20])
		}
		/**
		 * VIP等级 
		 * @param val
		 * 
		 */		
		public function set vipLevel(val:int):void
		{
			
			//SummonVIPLevel直接召唤5级镖车VIP等级
			if(_model.scene.Role.getVipLevel() >= _convoyObj["SummonVIPLevel"])
			{
				_myDis.chooseHeroBtn.visible	=	true;
			}
			else
			{
				_myDis.chooseHeroBtn.visible	=	false;
			}
			//InspireVIPLevel鼓舞VIP等级
			if(_model.scene.Role.getVipLevel() >= _convoyObj["InspireVIPLevel"])
			{
				_myDis.heroHelpBtn.visible	=	true;
				_myDis.heroLabel.visible	=	true;
			}
			else
			{
				_myDis.heroHelpBtn.visible	=	false;
				_myDis.heroLabel.visible	=	false;
			}
		}
		/**
		 * 是否有战神 
		 * @param val
		 * 
		 */		
		public function set playerConvoyCall(val:int):void
		{
			_playerConvoyCall		=	val;
			this.playerConvoyIndex	=	_playerConvoyIndex;
		}
		/**
		 * 邀请好友帮助了
		 */		
		public function setHelp():void
		{
//			_myDis.heplInfo.htmlStrByBorder	=	"<font size='14'>好友邀请中...</>";
			_myDis.heplInfo.x	= 74;
			_myDis.heplInfo.y	= 320;
			_myDis.heplInfo.htmlText	=	StaticIni.getSwfLangStr("UIString_1000539");
			_myDis.heplInfo.visible		=	true;
			_myDis.friendBox.visible	=	false;
			_myDis.friendBtn.enabled	=	true;
			_myDis.friendBtn.label		=	StaticIni.getSwfLangStr("UIString_1000540");
			_myDis.helpnameLab.visible	=	true;
			_myDis.helpnameLab.htmlText	=	_chooseFriendObj["name"];
		}
		/**
		 * 不用帮帮助 
		 */		
		public function getOut(isOk:Boolean=true):void
		{
			_time.stop();
//			_chooseFriendObj			=	null
			_myDis.heplInfo.x	= 74;
			_myDis.heplInfo.y	= 320;
			_myDis.heplInfo.visible		=	false;
			_myDis.friendBox.visible	=	true;
//			_myDis.friendBtn.visible	=	true;
			_myDis.friendBtn.enabled	=	true;
			_myDis.friendBtn.label		=	StaticIni.getSwfLangStr("UIString_1000541");
			_myDis.helpnameLab.visible	=	false;
			if(isOk==false)
			{
				AlertUI.showAlert("",StaticIni.getSwfLangStr("EscortStr_35"));
			}
			
			
		}
		/**
		 * 
		 *时间到了 
		 */	
		public function getOutTime():void
		{
			_time.stop();
			//			_chooseFriendObj			=	null
			_myDis.heplInfo.x	= 74;
			_myDis.heplInfo.y	= 320;
			_myDis.heplInfo.visible		=	false;
			_myDis.friendBox.visible	=	true;
			_myDis.helpnameLab.visible	=	false;
			_myDis.friendBtn.visible	=	true;
			_myDis.friendBtn.enabled	=	true;
			_myDis.friendBtn.label		=	StaticIni.getSwfLangStr("UIString_1000541");
			
			
		}
		/**
		 * 那哥们同意帮你了，快干活吧 
		 */		
		public function helpOK():void
		{
			_helpTime	=	60;
			_time.start();
			_myDis.friendBox.visible	=	false;
			_myDis.heplInfo.x	= 61;
			_myDis.heplInfo.y	= 320;
			_myDis.friendBtn.visible	=	false;
//			_chooseFriendObj			=	null;
		}
		/**
		 * 初始化 
		 */		
		private function init():void
		{
			_model		=	ModelLocator.getInstance();
			_model.addEventListener( SceneEvent.SceneLoaded, onSceneLoaded );
		}
		
		private function onSceneLoaded( evt : SceneEvent ):void
		{
			_model.removeEventListener( SceneEvent.SceneLoaded, onSceneLoaded );
			
			_friendListArray	=	[];
			_convoyObj			=	StaticIni.getIniObj("ConvoyPrize");
//			_myDis.p1.source	=	ResPath.SWF	+	"movemoneycar_1.swf";
//			_myDis.p2.source	=	ResPath.SWF	+	"movemoneycar_2.swf";
//			_myDis.p3.source	=	ResPath.SWF	+	"movemoneycar_3.swf";
//			_myDis.p4.source	=	ResPath.SWF	+	"movemoneycar_4.swf";
//			_myDis.p5.source	=	ResPath.SWF	+	"movemoneycar_5.swf";
			
			_myDis.name1.htmlText	=	StaticIni.getSwfLangStr("EscortName_0"+ 1);
			_myDis.name2.htmlText	=	StaticIni.getSwfLangStr("EscortName_0"+ 2);
			_myDis.name3.htmlText	=	StaticIni.getSwfLangStr("EscortName_0"+ 3);
			_myDis.name4.htmlText	=	StaticIni.getSwfLangStr("EscortName_0"+ 4);
			_myDis.name5.htmlText	=	StaticIni.getSwfLangStr("EscortName_0"+ 5);
			
			_myDis.p1.name		=	"p1";
			_myDis.p2.name		=	"p2";
			_myDis.p3.name		=	"p3";
			_myDis.p4.name		=	"p4";
			_myDis.p5.name		=	"p5";
			_myDis.friendInfoLabel.visible	=	true;
			_myDis.friendBtn.visible		=	false;
			_myDis.helpnameLab.visible		=	false;
			
			_myDis.heplInfo.x	= 74;
			_myDis.heplInfo.y	= 320;
//			_myDis.p1.scaleX	=	_myDis.p1.scaleY	=	1;
//			_myDis.p2.scaleX	=	_myDis.p2.scaleY	=	1;
//			_myDis.p3.scaleX	=	_myDis.p3.scaleY	=	1;
//			_myDis.p4.scaleX	=	_myDis.p4.scaleY	=	1;
//			_myDis.p5.scaleX	=	_myDis.p5.scaleY	=	1;
			
			
			
//			_myDis.p1.x  =_myDis.p1.y=0 ; 
//			trace(_myDis.p1.width)
//			_myDis.p2.x  =_myDis.p1.x+_myDis.p1.source.width ; 
//			_myDis.p2.y=0 ; 
//			_myDis.p3.x  =_myDis.p2.x +_myDis.p2.source.width;
//			_myDis.p3.y=0 ; 
//			_myDis.p4.x  =_myDis.p3.x +_myDis.p3.source.width;
//			_myDis.p4.y=0 ; 
//			_myDis.p5.x  =_myDis.p4.x+_myDis.p4.source.width;
//			_myDis.p5.y=0 ; 
			
			_friendObj	=	{};
			
			upDataFriendList();
			_time		=	new Timer(1000);
			
			_bindManage	=	BindManage.getInstance();
		
			_time		.addEventListener(TimerEvent.TIMER, timerHandle);
		}
		
		/**
		 * 添加好友
		 */		
		private function addFriend(PropertiesName:String,val:*,data:*):void
		{
			if(_friendObj[val[0]] == null)
			{
				var friendVo:FriendVo		=	new FriendVo();
				friendVo.name				=	val[0];
				friendVo.state				=	val[6];
				friendVo.sex				=	val[11];
				friendVo.level				=	val[5];
				friendVo.modeId				=	val[10];
				friendVo.escort				=	_maxNum - val[12];
				_friendObj[friendVo.name]	=	friendVo;
			}
			else
			{
				_friendObj[val[0]].name					=	val[0];
				_friendObj[val[0]].state				=	val[6];
				_friendObj[val[0]].sex					=	val[11];
				_friendObj[val[0]].level				=	val[5];
				_friendObj[val[0]].modeId				=	val[10];
				_friendObj[val[0]].escort				=	_maxNum - val[12];
			}
			upDataFriendList();
		}
		/**
		 * 移除好友 
		 */		
		private function removeFriend(PropertiesName:String,val:*,data:*):void
		{
			_friendObj[val[0]] = null;
			upDataFriendList();
		}
		/**
		 * 设定护送的使者特效 
		 * @param val
		 * 
		 */		
		private function setEffect(val:int):void
		{
			var itemPic:NxClip;
			for(var i :int = 1; i <= 5; i++)
			{
				itemPic			=	_myDis["p" + i] as NxClip
				itemPic.filters	=	[FilterUtil.GrayColorFilter];		
			}
			val = val <=0?1:val;
			itemPic			=	_myDis["p" + val] as NxClip;
			itemPic.filters	=	null;
			
			if(val == 5)
			{
				_myDis.refhBtn.enabled			=	false;
				_myDis.chooseHeroBtn.enabled	=	false;
			}
			else
			{
				_myDis.refhBtn.enabled			=	true;
				_myDis.chooseHeroBtn.enabled	=	true;
			}
		}
		/**
		 * 刷新好友列表
		 */		
		private function upDataFriendList():void
		{
			_myDis.friendBox.clear()
			_myDis.friendBox.addItem({label:StaticIni.getSwfLangStr("UIString_1000542"),data:null});	
			_countIndex	=	0;
			for(var i:int = 0; i < _friendListArray.length; i ++)
			{
				
				var itemObj:Object		=	_friendListArray[i] as Object;
				var statStr:String		=	"";
				var labelStr:String		=	"";
				if(itemObj["type"])
				{
					statStr	=	StaticIni.getSwfLangStr("UIString_1000543");
				}
				else
				{
					if(itemObj["count"] >= _convoyObj["helpNum"])
					{
						statStr	=	StaticIni.getSwfLangStr("UIString_1000544");
					}
					else
					{
						statStr	=	StaticIni.getSwfLangStrVar("UIString_1000545", [(_convoyObj["helpNum"]-itemObj["count"])]);
					}
				}
				labelStr	=	_friendListArray[i]["name"] + statStr;
				_myDis.friendBox.addItem({label:labelStr,data:itemObj});
				_countIndex++;
			}
//			_countIndex	=	0;
//			for(var item:String	 in _friendObj)
//			{
//				if(_friendObj[item] != null)
//				{
//					_countIndex	++;
//					var addItem:FriendVo	=	_friendObj[item] as FriendVo;
//					//是否在线
//					if(addItem.state)
//					{
//						var labelStr:String		=	addItem.sex == 0?"♀":"♂" + addItem.name + "剩余" + addItem.escort + "次";
//						_myDis.friendBox.addItem({label:labelStr,data:addItem});
//					}
//
//				}
//			}
			_countIndex++;
			_myDis.friendBox.showCount	=	_countIndex < _countMax?_countIndex : _countMax;
		}
		/**
		 * 请求事件 
		 * @param e
		 */		
		private function btnClickHandle(e:MouseEvent):void
		{
			var target:DisplayObjectContainer	=	e.currentTarget as DisplayObjectContainer
			switch(target)
			{
				case _myDis.sendBtn:
					//确认护送
					SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AFFIRM_CONVOY);
					_myDis.hide()
					break;
				case _myDis.refhBtn:
					//刷新
					SitAlerLogic.getIntatic().setUIinfo("			"+StaticIni.getSwfLangStrVar("EscortStr_20",[_playerConvoyMoney]), [], refBtnHandler, _myDis.refhBtn);
					break;
				case _myDis.friendBtn:
					//邀请好友
					if(_myDis.friendBtn.label == StaticIni.getSwfLangStr("UIString_1000541"))
					{
						if(_chooseFriendObj != null)
						{
							if(_chooseFriendObj["type"])
							{
								NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000546"))
							}
							else
							{
								if(_chooseFriendObj["count"] >= _convoyObj["helpNum"])
								{
									NoticeUI.getInstance().showInfo(StaticIni.getSwfLangStr("UIString_1000547"))
								}
								else
								{
									_myDis.friendBtn.enabled	=	false
									SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_INVITE_HELPER,[new WString(_chooseFriendObj["name"]),_playerConvoyIndex]);
									
								}
							}						
						}
					}
					else if(_myDis.friendBtn.label == StaticIni.getSwfLangStr("UIString_1000540"))
					{
						if(_chooseFriendObj != null)
						{
							_myDis.friendBtn.enabled	=	false;
							SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_HELP_CONVOY,[2,new WString(_chooseFriendObj["name"])]);
							getOut();
						}
					}

					break;
				case _myDis.heroHelpBtn:
					//鼓舞
					SitAlerLogic.getIntatic().setUIinfo("			" + StaticIni.getSwfLangStr("UIString_1000548"), [], heroHelpBtnHandler, _myDis.heroHelpBtn);
					break;
				case _myDis.chooseHeroBtn:
					//召唤
					SitAlerLogic.getIntatic().setUIinfo("			" + StaticIni.getSwfLangStr("UIString_1000549"), [], chooseHeroBtnHandler, _myDis.chooseHeroBtn);
					break;
			}
		}
		
		private function refBtnHandler():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AFFIRM_CHARGE,_reshHeroID);
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CHARGE,_reshHeroID);
			LogSendLogic.getInstance().btnClickNumSend(22818);
		}
		
		private function heroHelpBtnHandler():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AFFIRM_CHARGE,9);
			LogSendLogic.getInstance().btnClickNumSend(22820);
		}
		
		private function chooseHeroBtnHandler():void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_AFFIRM_CHARGE,7);
			LogSendLogic.getInstance().btnClickNumSend(22819);
		}
		
		/**
		 * 显示TIPS 
		 * @param e
		 * 
		 */		
		private  function btnOverClickHandle(e:MouseEvent):void
		{
			var target:DisplayObjectContainer	=	e.currentTarget as DisplayObjectContainer
			switch(target)
			{
				case _myDis.refhBtn:
					//刷新
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("EscortStr_20",[_playerConvoyMoney]));
					break;
				case _myDis.heroHelpBtn:
					//鼓舞
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("EscortStr_24",[10 +_playerConvoyExciteCount* 2 ]));
					break;
				case _myDis.chooseHeroBtn:
					//召唤
					TipsMainLogic.instance.showString(StaticIni.getSwfLangStr("EscortStr_26"));
					break;
				case _myDis.p1:
				case _myDis.p2:
				case _myDis.p3:
				case _myDis.p4:
				case _myDis.p5:
					((target as NxClip).content as MovieClip).play();
					//召唤
					showPipTips(target.name.slice(1,2))
					break;
			}
		}
		
		/**
		 * 关闭TIPS 
		 * @param e
		 * 
		 */		
		private function btnOutClickHandle(e:MouseEvent):void
		{		
			var target:DisplayObjectContainer	=	e.currentTarget as DisplayObjectContainer
			switch(target)
			{
				case _myDis.p1:
				case _myDis.p2:
				case _myDis.p3:
				case _myDis.p4:
				case _myDis.p5:
					((target as NxClip).content as MovieClip).stop();
					break;
			}
			
			TipsMainLogic.instance.hide();
		}
		/**
		 * 下拉框选择
		 */		
		private function comBoxClickHandle(e:NxComboBoxEvent):void
		{
			if(e.item["data"]	==	null)
			{
				_myDis.friendInfoLabel.visible	=	true;
				_myDis.friendBtn.visible		=	false;
			}
			else
			{
				_myDis.friendInfoLabel.visible	=	false;
				_myDis.friendBtn.visible		=	true;
			}
			_chooseFriendObj	=	e.item["data"] as Object
		}
		/**
		 * 关闭窗口
		 * @param e
		 * 
		 */		
		private function windowClose(e:NxWindowEvent):void
		{
			_myDis.hide();
		}
		/**
		 * 显示图片TIPS 
		 */		
		private function showPipTips(val:String):void
		{
			var itmeArray:Array	=	(_convoyObj[val] as String).split(",");
			TipsMainLogic.instance.showString(StaticIni.getSwfLangStrVar("EscortStr_25",
				[
					StaticIni.getSwfLangStr("EscortName_0"+ val),
					itmeArray[0] * _model.scene.Role.getPlayerLevel() + int(itmeArray[1]),
					itmeArray[2]
				])
				);
		}
		/**
		 * 刷新镖师要的钱 
		 * @param e
		 * 
		 */		
		private function upDataMoney(e:CustomMsgEvent):void
		{
			_playerConvoyMoney	=	e.pList[1];
		}
		/**
		 * 刷新好友中在线的人员 
		 * @param e
		 * 
		 */		
		private function upFriednHelpList(e:CustomMsgEvent):void
		{
			var friendList:Array	=	e.pList;
			_friendListArray		=	[];
			for(var i :int =0; i< friendList.length; i+= 4)
			{
				if(friendList[i+3]>=45)
				{
					var itemObj:Object	=	{};
					itemObj["name"]		=	friendList[i];
					itemObj["count"]	=	friendList[i+1];
					itemObj["type"]		=	friendList[i+2];
					_friendListArray.push(itemObj);
				}
				
			}
			upDataFriendList();
		}
		/**
		 *  有效时间计时
		 */		
		private function timerHandle(e:TimerEvent):void
		{
			if(_helpTime <= 0)
			{
				_time.stop();
				getOut();
			}
			else
			{
				_myDis.heplInfo.htmlStrByBorder	=	StaticIni.getSwfLangStrVar("EscortStr_31",[_helpTime])
				_helpTime--;
			}

			
		}
	}
}